package br.ufrj.ppgi.greco.model.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import br.com.caelum.vraptor.ioc.Component;
import br.ufrj.ppgi.greco.model.entity.EntityService;

@Component
public class DAOService extends DAOGeneric<EntityService>
{
	private EntityManager em;
	
	public DAOService(EntityManager em)
	{
		super(em);
		this.em = em;
	}
	
	
	public EntityService getServiceByURL(String service)
	{
		String querySearch = "select es from " + EntityService.class.getSimpleName() + " es where es.service = :service";
		Query q = this.em.createQuery(querySearch);
		q.setParameter("service", service);
		
		return (EntityService) q.getSingleResult();
	}
	
	
	public String getAllServicesJson()
	{
		String result = "[";
		List<EntityService> listServices=  this.getAll();
		for(EntityService serv : listServices)
		{
			result+= "'"+serv.getService()+"',";
		}	
		result += "];";
		return result;
	}

}
